﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace MangoMes.Write.API.Applications.CraftRoutes
{
    public class CraftRouteAddHandler : IRequestHandler<CraftRouteAddCommand, int>
    {
        private readonly IBateRepository<CraftRoute> craf;
        public CraftRouteAddHandler(IBateRepository<CraftRoute> craf)
        {
            this.craf = craf;
        }

        /// <summary>
        /// 工艺管理新增
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(CraftRouteAddCommand request, CancellationToken cancellationToken)
        {
            DapperHelper helper=new DapperHelper();
            CraftRoute craftroute=new CraftRoute();
            craftroute.RouteNo =request .RouteNo;
            craftroute.RouteName = request.RouteName;
            craftroute.Comment = request.Comment;
            craftroute.RouteExplain = request.RouteExplain;   
            craftroute.IsNo= request.IsNo;
            string conn = helper.MangoMesWrite;
            string str= $"insert into craftroute values (@RouteId,@RouteNo,@RouteName,@RouteExplain,@IsNo,@Comment)";
            var ai = await craf.Add(str, craftroute, conn);

            return ai;
        }
    }
}
